package com.yy.springcloud.controller;

import com.yy.springcloud.dao.PaymentDao;
import com.yy.springcloud.entity.CommonResult;
import com.yy.springcloud.entity.Payment;
import com.yy.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("payment")
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    @Autowired
    private PaymentDao paymentDao;

    @Autowired
    private PaymentService paymentService;

    @Autowired
//    springcloud中的服务发现
    private DiscoveryClient discoveryClient;

    @GetMapping("get")
    public CommonResult<Payment> getPayment(){
        long count = paymentService.count();
        List<Payment> payments = paymentDao.selectList(null);
        return new CommonResult<Payment>(200,"success,serverPort: " + serverPort ,payments.get(0));
    }

    @GetMapping("discovery")
    public DiscoveryClient getDiscoveryClient(){
        return this.discoveryClient;
    }
}
